package com.jie.other.ui.list_choose_dialog

import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.sizeIn
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp

@Composable
fun ListChooseDialogView(
    mList: List<ListItemDTO>,
    maxHeight: Int,
    itemClickListener: ((Int, ListItemDTO) -> Unit)? = null,
    cancelClickListener: (() -> Unit)? = null,
    modifier: Modifier = Modifier,
) {
    Column(modifier = modifier
        .padding(13.dp)
    ) {
        ListChooseListView(
            list = mList,
            itemClickListener = itemClickListener,
            modifier = Modifier
                .background(
                    Color.White,
                    RoundedCornerShape(10.dp)
                )
                .sizeIn(maxHeight = maxHeight.dp)
        )
        Box(Modifier.height(10.dp))
        Column(
            modifier = Modifier
                .fillMaxWidth()
                .background(
                    Color.White,
                    RoundedCornerShape(10.dp)
                )
                .clickable {
                    cancelClickListener?.invoke()
                },
            horizontalAlignment = Alignment.CenterHorizontally
        ){
            Text(
                text = "取消",
                color = Color.LightGray,
                modifier = Modifier.padding(13.dp)
            )
        }
    }
}

@Preview(showBackground = true, backgroundColor = 0x000000)
@Composable
fun previewListChooseDialogView() {
    ListChooseDialogView(
        mList = mutableListOf<ListItemDTO>().apply {
            add(ListItemDTO("0", "选项1"))
            add(ListItemDTO("1", "选项2"))
        },
        60,
        { post, item -> },
        null
    )
}